home *** CD-ROM | disk | FTP | other *** search
- /***************************************************************
- ADOBE SYSTEMS INCORPORATED
- Copyright 2002 Adobe Systems Incorporated
- All Rights Reserved
-
- NOTICE: Adobe permits you to use, modify, and distribute this
- file in accordance with the terms of the Adobe license agreement
- accompanying it. If you have received this file from a source
- other than Adobe, then your use, modification, or distribution
- of it requires the prior written permission of Adobe.
- ***************************************************************/
-
- /***************************************************************
- Author: Henry Lee
- Revised by: Ken Villines
- ***************************************************************/
-
- /***************************************************************
-
- This is a simple function that takes an LMTextObject (point or
- box text) and converts the paragraph into words. The words are
- created from converting the text object into individual characters
- then regrouped into words.
-
- Functions:
- breakApartWords(target)
-
- Arguments:
- <target> LMTextObject - The text object to be broken apart
-
- ***************************************************************/
-
- //comp = application.currentComposition;
- //objs = comp.selection;
-
- /***************************************************************
- To change the behavior of this script,
- make your changes below
- ***************************************************************/
- Console.hide();
- Console.clear();
-
- if(application.compositions.length >= 1){
-
- comp = application.currentComposition;
-
- if(comp.selection.length < 1){
- Console.show();
- Console.clear();
- Console.write("ERROR: Nothing is selected");
- }else{
- objs = comp.selection;
-
- if(objs.length > 1){
- Console.show();
- Console.clear();
- Console.write("ERROR: More then one object is selected");
- }else{
- returnKey = /\r/;
- newLine = /\n/;
- formFeed = /\f/;
-
- for (var i=0;i<objs.length;i++) {
- if(objs[i].toString() == "[object LMPointTextObject]" ||
- objs[i].toString() == "[object LMBoxTextObject]"){
- if(objs[i].text.search(returnKey) == (-1) &&
- objs[i].text.search(newLine) == (-1) &&
- objs[i].text.search(formFeed) == (-1)){
- breakApartWords(comp.selection[i]);
- }else{
- Console.show();
- Console.clear();
- Console.write("ERROR: A return character was found");
- }
- }else{
- Console.show();
- Console.clear();
- Console.write("ERROR: A text object was not Selected");
- }
- }
- }
- }
- }else{
- Console.show();
- Console.clear();
- Console.write("ERROR: A Composition does not exist");
- }
-
- /***************************************************************
- DO NOT EDIT BELOW THIS LINE
- ***************************************************************/
-
-
- // class definition
- function Word(x,y) {
- this.startIndex = x;
- this.endIndex = y;
- }
-
- function breakApartWords(target) {
-
- // regular expression: any word: [a-zA-Z]+
-
- var origText = target.text;
- var results;
- var pattern;
- var startIndex = new Array;
- var endIndex = new Array;
- var temp;
- var inWord = false;
- var j=0;
- var tempWord;
- var tempWordArray = new Array;
- var k=0;
- var linenum=0;
- var words = new Array;
-
- characterArray = target.convertIntoObjects();
- characterGroup = comp.group(characterArray);
- characterGroup.name = "Group of Words";
- characters = characterGroup.objects;
-
- pattern = /\S/;
-
- for (var i=0; i<origText.length; i++) {
- temp = origText.charAt(i);
- if (temp.match(pattern)) { //not whitespace
- if (!inWord) {
- inWord = true;
- words[j] = new Word(i-(2*linenum),0);
- }
- }
- else { //white space
- if (inWord) {
- inWord = false;
- words[j].endIndex = i-1-(2*linenum);
- j++;
- }
- }
- if (i==origText.length-1) { //there is no white space at the end of a text block
- if (inWord) {
- inWord = false;
- words[j].endIndex = i-(2*linenum);
- j++;
- }
- }
- //when text is broken up, the newline & return character codes are lost
- //this creates a difference in the character indices between the original
- //text block and the character array.
- if ((origText.charCodeAt(i)==13)&&(origText.charCodeAt(i+1)==10)) {
- linenum++;
- }
- }
-
- for (j=0; j<words.length;j++) {
- k=0;
- var tempName = "";
- tempWordArray=new Array();
- for (i=words[j].startIndex;i<=words[j].endIndex;i++) {
- tempWordArray[k]=characters[i];
- tempName += characters[i].text;
- k++;
- var whiteSpace = characters[i+1];
- }
-
- if(i+1 <= characters.length){
- whiteSpace.deleteThisObject();
- }
-
- var tempWord = comp.group(tempWordArray);
- tempWord.name = tempName;
- }
-
- return linenum;
- }
-